<template>
  <div>
    <!-- 卡片 -->
    <el-card class="box-card" style="margin-top: 15px">
      <div style="margin-bottom: 15px; display: flex">
        <span>航空公司代码：</span>
        <el-input v-model="selectinput" size="mini" style="width: 200px" placeholder="请输入内容"></el-input>
        <el-button type="primary" size="mini" @click="search">查询</el-button>
        <el-button type="primary" size="mini" @click="centerDialogVisible = true">添加</el-button>
      </div>
      <!-- 用户列表区 -->
      <el-table size="mini" :header-cell-style="{
          color: '#fff',
          background: '#6090EC',
          fontSize: '11px',
          fontWeight: 'normal',
        }" id="tableTop" :data="airportLists" border stripe>
        <el-table-column label="航空公司代码" prop="airlinerId"></el-table-column>
        <el-table-column label="航空公司" prop="airliner"></el-table-column>
        <el-table-column label="简称" prop="airlinerShorter"></el-table-column>
        <el-table-column label="国内外" prop="isInland">
          <template slot-scope="scope">
            <template v-if="scope.row.isInland == '0'">国内</template>
            <template v-if="scope.row.isInland == '1'">国外</template>
          </template>
        </el-table-column>
        <el-table-column label="国家" prop="countryName"></el-table-column>

        <el-table-column label="客服电话" prop="servicePhone"></el-table-column>
        <el-table-column label="联系信息" prop="contactInfo"></el-table-column>
        <el-table-column label="操作" width="180px">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="watcheditairliner(scope.row)">修改</el-button>
            <el-button type="primary" size="mini" @click="delcomfig(scope.row)">删除</el-button>

          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 确认删除 -->
    <el-dialog title="提示" :visible.sync="comfigdelDialogVisible" :close-on-click-modal="false" width="30%" center>
      <span>确认删除此条数据吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="comfigdelDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="getdeleteAirLinerById()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 新增 -->
    <el-dialog title="添加航空公司" :visible.sync="centerDialogVisible" :close-on-click-modal="false" width="50%" center>
      <el-form :inline="true" :model="addairline" class="demo-form-inline" :rules="rules">
        <el-form-item label="公司代码 ：" prop="airlinerId">
          <el-input size="mini" v-model="addairline.airlinerId" placeholder="公司代码"></el-input>
        </el-form-item>
        <el-form-item label="航空公司 ：" prop="airliner">
          <el-input size="mini" v-model="addairline.airliner" placeholder="航空公司"></el-input>
        </el-form-item>
        <el-form-item label="公司简称 ：" prop="airlinerShorter">
          <el-input size="mini" v-model="addairline.airlinerShorter" placeholder="公司简称"></el-input>
        </el-form-item>
        <el-form-item label="国家名称 ：">
           <foreign-area :popularCity=" { value:'CN',label:'中国'}"  @selectcountry="selectFnCountry($event,'addairline','countryId')"></foreign-area>
        </el-form-item>
        <el-form-item label="公司类型 : " style="margin-right: 50px">
          <el-radio v-model="addairline.isInland" label="0">国内</el-radio>
          <el-radio v-model="addairline.isInland" label="1">国外</el-radio>
        </el-form-item>
        <el-form-item label="结算码 ：" prop="balanceCode">
          <el-input size="mini" v-model="addairline.balanceCode" placeholder="结算码"></el-input>
        </el-form-item>
        <el-form-item label="客服电话 ：" prop="servicePhone">
          <el-input size="mini" v-model="addairline.servicePhone" placeholder="客服电话"></el-input>
        </el-form-item>
        <el-form-item label="联系信息 ：" prop="contactInfo">
          <el-input type="textarea" :autosize="{ minRows: 3 }" size="medium" v-model="addairline.contactInfo"
            placeholder="联系信息"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="getaddairliner()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 修改 -->
    <el-dialog title="修改航空公司" :visible.sync="editcenterDialogVisible" :close-on-click-modal="false" width="50%" center>
      <el-form :inline="true" :model="editairline" class="demo-form-inline" :rules="rules">
        <el-form-item label="公司代码 ：" prop="airlinerId">
          <el-input size="mini" v-model="editairline.airlinerId" placeholder="公司代码"></el-input>
        </el-form-item>
        <el-form-item label="航空公司 ：" prop="airliner">
          <el-input size="mini" v-model="editairline.airliner" placeholder="航空公司"></el-input>
        </el-form-item>
        <el-form-item label="公司简称 ：" prop="airlinerShorter">
          <el-input size="mini" v-model="editairline.airlinerShorter" placeholder="公司简称"></el-input>
        </el-form-item>
        <el-form-item label="国家名称 ：">
           <foreign-area :popularCity=" { value:'CN',label:'中国'}"  @selectcountry="selectFnCountry($event,'editairline','countryId')"></foreign-area>
        </el-form-item>
        <el-form-item label="公司类型 : " style="margin-right: 50px">
          <el-radio v-model="editairline.isInland" label="0">国内</el-radio>
          <el-radio v-model="editairline.isInland" label="1">国外</el-radio>
        </el-form-item>
        <el-form-item label="结算码 ：" prop="balanceCode">
          <el-input size="mini" v-model="editairline.balanceCode" placeholder="结算码"></el-input>
        </el-form-item>
        <el-form-item label="客服电话 ：" prop="servicePhone">
          <el-input size="mini" v-model="editairline.servicePhone" placeholder="客服电话"></el-input>
        </el-form-item>
        <el-form-item label="联系信息 ：" prop="contactInfo">
          <el-input type="textarea" :autosize="{ minRows: 3 }" size="medium" v-model="editairline.contactInfo"
            placeholder="联系信息"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelEdit()">取 消</el-button>
        <el-button type="primary" @click="methodsss()">确 定</el-button>
        <!--geteditairliner(),  -->
      </span>
    </el-dialog>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
      :page-sizes="[10, 15, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="pageTotal">
    </el-pagination>
  </div>
</template>

<script>
  import foreignArea from "@/components/sw-area/foreignArea.vue"
  export default {
    data() {
      return {
        format: "yyyy-MM-dd",
        // 修改使用的主键id
        editid: "",
        // 删除使用的主键id
        delid: "",
        //分页
        pageSize: 10,
        currentPage: 1,
        pageTotal: 0,

        // 表单验证规则
        rules: {
          airlinerId: [{
            required: true,
            message: "请输入公司代码",
            trigger: "change"
          }, ],
          airliner: [{
            required: true,
            message: "请输入航空公司",
            trigger: "change"
          }, ],
          airlinerShorter: [{
            required: true,
            message: "请输入公司简称",
            trigger: "change"
          }, ],
          balanceCode: [{
            required: true,
            message: "请输入结算吗",
            trigger: "change"
          }],
          servicePhone: [{
            required: true,
            message: "请输入客服电话",
            trigger: "change"
          }, ],
          contactInfo: [{
            required: true,
            message: "请输入联系信息",
            trigger: "change"
          }, ],
        },

        // 弹窗显示
        centerDialogVisible: false,
        editcenterDialogVisible: false,
        comfigdelDialogVisible: false,
        // 添加公司
        addairline: {
          servicePhone: "", //客服电话
          airlinerId: "", //航空公司代码
          countryId: "CN", //国家Id
          airliner: " ", //航空公司名称
          airlinerShorter: "", //简称
          isInland: "0", //国内/国外
          contactInfo: "", //联系信息
          balanceCode: "", //码
        },
        // 修改公司
        editairline: {
          servicePhone: "", //客服电话
          airlinerId: "", //航空公司代码
          countryId: "CN", //国家Id
          airliner: " ", //航空公司名称
          airlinerShorter: "", //简称
          isInland: "0", //国内/国外
          contactInfo: "", //联系信息
          balanceCode: "", //码
        },
        selectinput: "",
        // 航司列表
        airportLists: [],
      };
    },
    components:{
      foreignArea
    },
    watch: {},
    methods: {
      // 国籍
      selectFnCountry(data,index,key){
        this[index][key] = data;
      },
      // 确认删除事件
      delcomfig(row) {
        this.comfigdelDialogVisible = true;
        console.log(row);
        this.delid = row.id;
      },
      // 修改数据
      watcheditairliner(row) {
        console.log(row);
        this.editid = row.id;
        this.editcenterDialogVisible = true;
        this.editairline = row
        //  this.editairline.countryId = row.countryId
        console.log(this.editairline)
      },
      cancelEdit(){
        this.editcenterDialogVisible = false 
        this.search()
      },

      //分页
      handleSizeChange(value) {
        console.log("1", value);
        this.getairportList();
        this.pageSize = value;
      },
      handleCurrentChange(value) {
        console.log("2", value);
        this.currentPage = value;
        this.getairportList();
        // orders = res.data;
      },
      search() {
        this.getairportList();
      },
      // 航司列表接口
      getairportList() {
        this.$axios.getairportList({
          airlinerId: this.selectinput,
          pageNo:this.currentPage
        }).then((res) => {
          console.log(res);
          // debugger
          if (res.code == "00000") {
            this.airportLists = res.data.records;
            this.pageTotal = res.data.total
          }
        });
      },
      // 新增航司
      getaddairliner() {
        if (
          this.addairline.servicePhone != "" &&
          this.addairline.airlinerId != "" &&
          this.addairline.countryId != "" &&
          this.addairline.airliner != "" &&
          this.addairline.airlinerShorter != "" &&
          this.addairline.isInland != "" &&
          this.addairline.contactInfo != "" &&
          this.addairline.balanceCode != ""
        ) {
          this.$axios
            .getaddairliner({
              servicePhone: this.addairline.servicePhone, //客服电话
              airlinerId: this.addairline.airlinerId, //航空公司代码
              countryId: this.addairline.countryId, //国家Id
              airliner: this.addairline.airliner, //航空公司名称
              airlinerShorter: this.addairline.airlinerShorter, //简称
              isInland: this.addairline.isInland, //国内/国外
              contactInfo: this.addairline.contactInfo, //联系信息
              balanceCode: this.addairline.balanceCode, //结算码
            })
            .then((res) => {
              console.log(res);
              if (res.code == "00000") {
                this.centerDialogVisible = false;
                this.getairportList()
                this.$message({
                  message: "添加成功",
                  type: "success",
                });
              }
            });
        } else {
          this.$message.error("请认真填写添加信息");
        }
      },
      // 删除航司
      getdeleteAirLinerById() {
        this.$axios
          .getdeleteAirLinerById({
            id: this.delid,
          })
          .then((res) => {
            console.log(res);
            if (res.code == "00000") {
              this.comfigdelDialogVisible = false;
              this.getairportList()
              this.$message({
                message: "删除成功",
                type: "success",
              });
            }
          });
      },
      methodsss() {
        console.log(this.editairline)
        this.geteditairliner()
      },
      // 修改航司
      geteditairliner() {
        if (
          this.editairline.servicePhone != "" &&
          this.editairline.airlinerId != "" &&
          this.editairline.countryId != "" &&
          this.editairline.airliner != "" &&
          this.editairline.airlinerShorter != "" &&
          this.editairline.isInland != "" &&
          this.editairline.contactInfo != "" &&
          this.editairline.balanceCode != ""
        ) {
          this.$axios
            .geteditairliner({
              servicePhone: this.editairline.servicePhone, //客服电话
              airlinerId: this.editairline.airlinerId, //航空公司代码
              countryId: this.editairline.countryId, //国家Id
              airliner: this.editairline.airliner, //航空公司名称
              airlinerShorter: this.editairline.airlinerShorter, //简称
              isInland: this.editairline.isInland, //国内/国外
              contactInfo: this.editairline.contactInfo, //联系信息
              balanceCode: this.editairline.balanceCode, //结算码
              id: this.editid, //主键id
            })
            .then((res) => {
              console.log(res);
              if (res.code == "00000") {
                this.editcenterDialogVisible = false;
                this.getairportList()
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
              }
            });
        } else {
          this.$message.error("请认真填写修改信息");
        }
      },
    },

    mounted() {
      // 航司列表
      this.getairportList();
    },
  };
</script>
<style scoped>
  el-table-column {
    background-color: #f2f2f2;
  }

  #searchBtn {
    background-color: #54dac9;
    color: #fff;
  }
</style>